package com.kobi.tapeRecorder;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;

public class SettingActivity extends Activity {
	
	private RadioButton radio_none;
	private RadioButton radio_1;
	private RadioButton radio_5;
	private RadioButton radio_10;
	
	private int chosen;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_settings);
		
		radio_none = (RadioButton) findViewById(R.id.radio_none);
		radio_1 = (RadioButton) findViewById(R.id.radio_1);
		radio_5 = (RadioButton) findViewById(R.id.radio_5);
		radio_10 = (RadioButton) findViewById(R.id.radio_10);
		
		Intent i = getIntent();
		chosen = i.getIntExtra(MainActivity.RECORD_LENGTH, MainActivity.RADIO_NONE);
		
		if (chosen == MainActivity.RADIO_NONE)
			radio_none.setChecked(true);
		else if (chosen == MainActivity.RADIO_1)
			radio_1.setChecked(true);
		else if (chosen == MainActivity.RADIO_5)
			radio_5.setChecked(true);
		else if (chosen == MainActivity.RADIO_10)
			radio_10.setChecked(true);
	}
	
	public void onRadioButtonClicked(View view) {
	    // Is the button now checked?
	    boolean checked = ((RadioButton) view).isChecked();
	    
	    // Check which radio button was clicked
	    switch(view.getId()) {
	        case R.id.radio_none:
	            if (checked)
	            	chosen = MainActivity.RADIO_NONE;
	            break;
	        case R.id.radio_1:
	            if (checked)
	            	chosen = MainActivity.RADIO_1;
	            break;
	        case R.id.radio_5:
	            if (checked)
	            	chosen = MainActivity.RADIO_5;
	            break;
	        case R.id.radio_10:
	            if (checked)
	            	chosen = MainActivity.RADIO_10;
	            break;
	    }
	}
	
	
	@Override
	public void onBackPressed() {
		Intent intent = new Intent();
	    
	    Bundle bundle = new Bundle();
	    bundle.putInt(MainActivity.RECORD_LENGTH, chosen);
	    intent.putExtras(bundle);
	    
	    if (getParent() == null) {
	        setResult(Activity.RESULT_OK, intent);
	    } else {
	        getParent().setResult(Activity.RESULT_OK, intent);
	    }
		super.onBackPressed();
	}

	
	
}
